import 'package:flutter/material.dart';
/*
1.管理自己状态
2.定义_active：确定盒子的当前颜色的布尔值
3.定义_handleTap()函数，该函数在点击该盒子时更新_active，并调用setState()更新ui
4.实现widget的所有交互行为
 */
class Exam_1 extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Scaffold(
      appBar: AppBar(
        title: Text("Widget管理自身状态"),
      ),
      body: TapboxA(),
    );
  }

}



class TapboxA extends StatefulWidget{

  TapboxA({Key key}) : super(key:key);
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return new _TapboxState();
  }

}

class _TapboxState extends State<TapboxA>{

  bool _actice = false;

  void _handleTap(){
    setState(() {
      _actice = !_actice;
    });
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new GestureDetector(
      onTap: _handleTap,
      child: new Container(
        child: new Center(
          child: new Text(
            _actice? 'Active': 'Inactice',
            style: new TextStyle(fontSize: 32.0,color: Colors.white),
          ),
        ),
        width: 200.0,
        height: 200.0,
        decoration: new BoxDecoration(
          color: _actice ? Colors.lightGreen[700]:Colors.grey[600]
        ),
      ),
    );
  }

}